#ifndef EigenFiltFiltTest_h
#define EigenFiltFiltTest_h

#include <btkEigen/SignalProcessing/FiltFilt.h>
#include <btkEigen/SignalProcessing/IIRFilterDesign.h>
#include <btkConvert.h>

#include "EigenFilt_Util.h"

CXXTEST_SUITE(EigenFiltFiltTest)
{
  CXXTEST_TEST(Butterworth_LowPass_2_0Dot5)
  {
    Eigen::Matrix<double,Eigen::Dynamic,1> x;
    generateRawData(x);
    Eigen::Matrix<double,Eigen::Dynamic,1> a,b;
    btkEigen::butter(&b, &a, 2, 0.5);
    Eigen::Matrix<double,Eigen::Dynamic,1> y = btkEigen::filtfilt(b, a, x);
    // Note: the data in the 'result' variable were computed with a different algorithm than the one implemented in BTK.
    Eigen::Matrix<double,Eigen::Dynamic,1> result(81,1);
    result << 0.269798891254315, 0.548893273936043, 0.859470031283581, 1.083314451319253, 1.181526336501076, 1.257304313666979, 1.276759551809656, 1.068465704696009, 0.685668156305006, 0.372268495814636, 
              0.157220415283078,-0.104162709960200,-0.411133031729557,-0.666435823989357,-0.821984136929495,-0.833236901328857,-0.709580252798482,-0.542015408017795,-0.372916081515782,-0.174340534581690, 
              0.072920410968047, 0.380822922154266, 0.767727734946687, 1.120370101251430, 1.245206330432570, 1.175867152632213, 1.092613558545766, 1.006391390249807, 0.809008427785796, 0.500882870473192,
              0.177427442323182,-0.115265050765107,-0.399394457537441,-0.683974764754652,-0.867972546429597,-0.841912916291380,-0.686986990511049,-0.548614709893092,-0.431855109908579,-0.225316251342442,
              0.149990554410562, 0.548991274928445, 0.766603662161258, 0.897492808926710, 1.119235616431332, 1.308820691731916, 1.244650590294634, 0.982001470310733, 0.740054381757683, 0.537145589228529,
              0.241231226499049,-0.153720986008040,-0.506910201501367,-0.663739279012461,-0.656372165803181,-0.667496462570363,-0.676804487342212,-0.520053642587747,-0.227506579633197, 0.073377651136435, 
              0.334500818135176, 0.537846810887783, 0.716580939359015, 0.908624646571194, 1.038847705160293, 1.081244298319416, 1.110278804941418, 1.053114775703411, 0.816052544461935, 0.519935281836539,
              0.261179617911776,-0.018178988662816,-0.328756149855888,-0.622570989208225,-0.849673221482816,-0.901019340312481,-0.760265237435191,-0.571478064861968,-0.381544623107748,-0.141512050095412,
              0.126109968176025;
    
    TS_ASSERT_EQUALS(x.rows(), y.rows());
    TS_ASSERT_EQUALS(x.cols(), y.cols());
    for (int i = 0 ; i < x.rows() ; ++i)
      TSM_ASSERT_DELTA("Sample #" + btk::ToString(i), y.coeff(i), result.coeff(i), 5e-15); // Sample #74 doesn't pass the 1e-15 accuracy
  };
  
  CXXTEST_TEST(Butterworth_LowPass_7_0Dot4)
  {
    Eigen::Matrix<double,Eigen::Dynamic,1> x;
    generateRawData(x);
    Eigen::Matrix<double,Eigen::Dynamic,1> a,b;
    btkEigen::butter(&b, &a, 7, 0.4);
    Eigen::Matrix<double,Eigen::Dynamic,1> y = btkEigen::filtfilt(b, a, x);
    
    // Note: the data in the 'result' variable were computed with a different algorithm than the one implemented in BTK.
    Eigen::Matrix<double,Eigen::Dynamic,1> result(81,1);
    result << 0.269224198995365, 0.576244844891377, 0.841047794985662, 1.051995960896665, 1.212111883898300, 1.294908320869989, 1.243866016500979, 1.033629026285214, 0.719179022882040, 0.399382497299564, 
              0.127932072638959,-0.121258223148020,-0.390804362682516,-0.657304120320415,-0.831609306644179,-0.843293620017637, -0.712549898485055,-0.529036301998747,-0.360748067274338,-0.190361216247611,
              0.053347648952137, 0.401417302063049, 0.787555567463439, 1.090074745480490, 1.228940660982778, 1.215991998981691, 1.114686623121020, 0.968446370750735, 0.777129373378568, 0.526670672267367, 
              0.219499035562998,-0.120036382087887,-0.447100626602707,-0.699361700915987,-0.823207735761345, -0.814721264794714,-0.722096588753804,-0.590551496751037,-0.414688555193363,-0.164553676607189, 
              0.150375976153217, 0.471982978120317, 0.750129529922342, 0.977292533968083, 1.152390006271393, 1.240240161208414, 1.198919420272117, 1.034279429003080, 0.794108089568890, 0.511288333138874, 
              0.187671284807061,-0.157001067998262,-0.455439925580662,-0.640566143770464,-0.707277695676099,-0.698482283199390,-0.635717283921607,-0.493799769779159,-0.252431539275415, 0.050937965124214, 
              0.339723617914652, 0.563249498589249, 0.729730708532069, 0.876377096262877, 1.016818678478446, 1.119098490061520, 1.129646406510832, 1.018682400148089, 0.806334782897612, 0.543803793466131,
              0.267131175629460,-0.024386300271966,-0.336456307657096,-0.632556662982100,-0.835389016593736,-0.884215372399933,-0.784026327097787,-0.591847281576759,-0.363022441619061,-0.121385501896644, 
              0.127102732446800;
    
    TS_ASSERT_EQUALS(x.rows(), y.rows());
    TS_ASSERT_EQUALS(x.cols(), y.cols());
    for (int i = 0 ; i < x.rows() ; ++i)
      TSM_ASSERT_DELTA("Sample #" + btk::ToString(i), y.coeff(i), result.coeff(i), 5e-14); // Few samples doesn't pass the 1e-14 accuracy.
  };
  
  CXXTEST_TEST(FiltFiltWindowAverage_FixedSize)
  {
    Eigen::Matrix<double, 16, 1> signal, ref;
    signal << 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6, 2.8, 3.0, 3.2, 3.4, 3.6, 3.8, 4.0;
    ref = signal;
    Eigen::Matrix<double, 5, 1> b = Eigen::Matrix<double, 5, 1>::Constant(0.2); // ones(5,1) / 5
    Eigen::Matrix<double, 1, 1> a; a << 1.0;
    signal = btkEigen::filtfilt(b, a, signal);
    for (int i = 0 ; i < signal.rows() ; ++i)
    {
      TSM_ASSERT_DELTA("Row #" + btk::ToString(i), signal(i), ref(i), 1e-15);
    }
  }
  
  CXXTEST_TEST(FiltFiltOrder2_FixedSize)
  {
    Eigen::Matrix<double, 16, 1> signal;
    signal << 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4, 2.6, 2.8, 3.0, 3.2, 3.4, 3.6, 3.8, 4.0;
    Eigen::Matrix<double, 2, 1> b; b << 1.0, -1.0;
    Eigen::Matrix<double, 2, 1> a; a << 1.0, -0.995;
    signal = btkEigen::filtfilt(b, a, signal);
    Eigen::Matrix<double, 16, 1> ref;
    ref << -3.261004362208549, -3.079386318802563, -2.897845646912123, -2.716377785213817, -2.534978174213632, -2.353642256132397, -2.172365474791265, -1.991143275497240, -1.809971104928730, -1.628844411021146, -1.447758642852533, -1.266709250529219, -1.085691685071496, -0.904701398299327, -0.723733842718070, -0.542784471404218;
    for (int i = 0 ; i < signal.rows() ; ++i)
    {
      TSM_ASSERT_DELTA("Row #" + btk::ToString(i), signal(i), ref(i), 1e-15);
    }
  }
  
  CXXTEST_TEST(FiltFiltECG_FixedSize)
  {
    Eigen::Matrix<double, 500, 1> signal;
    signal << 0.045806815750359, -0.257168512463552, 0.237852204638961, 0.077585600070984, 0.034887229237275, 0.130178451021726, 0.066991821582462, -0.233457828742139, -0.038397430776135, -0.034053297729956, -0.130269109921177, 0.423533006374925, -0.215651855402771, -0.117399907962194, -0.174173909263417, -0.289452481442662, -0.043685904535174, -0.063870209205403, 0.387438850311874, -0.057062090494475, -0.260585884660276, 0.406605166520170, 0.314684002140956, -0.051119023894431, -0.369978963720463, -0.104322618409177, -0.031877549800520, 0.076398146041659, -0.057636455457242, 0.118783307641004, 0.106174755201196, -0.304195150435415, -0.219334863351220, -0.158440365293012, -0.090937438417001, -0.034946136537065, 0.057495791413851, -0.693735013317138, -0.041513547223545, 0.392533005552487, -0.175573654830933, 0.333714526543516, 0.197043527175186, 0.111392626869429, 0.173437900633558, -0.254258353820167, 0.125051570723535, 0.556353819289138, 0.189134966258897, 0.184072216931726,
              -0.000632673654411, 0.184386962977146, 0.259357939596797, 0.317048866753366, 0.126430582930706, 0.169699913382737, 0.743917071933249, -0.317413351381110, 0.813717352317615, 0.349927648317118, 0.524732719021575, -0.132142813662019, 0.145570454993892, 0.232743846064322, 0.417119600771221, -0.096928705536064, 0.447710841491081, 0.035771250928843, 0.346349771993158, 0.483710441091897, 0.393205669760374, 0.572918263064839, 0.544598373749961, 0.121171370935308, 0.338981553482786, 0.029442271562787, -0.074091198144751, 0.478381624616364, 0.238006812551299, 0.215083830669682, 0.447414584775047, 0.359097901753393, 0.288821479909312, 0.504653202556475, 0.415356969159203, 0.233669627823967, -0.008042253178936, -0.007521178799152, 0.444211908310784, -0.265951947451939, 0.121709374598083, -0.368567726428115, 0.364587780449322, 0.315711561474061, 0.091392215786133, 0.064211600664682, -0.548830867181469, 0.208852402702879, -0.493730198918030, -0.534622336547831,
              0.056000376727152, -0.210284087700536, 0.120528022587482, 0.177719027692194, 0.222723482653586, -0.164683664912439, 0.120266292306083, 0.032895994174200, 0.214070926293973, 0.141408466739033, 0.231657073334884, -0.025983730061469, -0.029983857037080, 0.258575628408158, -0.524465818441078, -0.119882784134582, -0.311569025127183, -0.089750843270869, 0.167880942999259, 0.211958684878605, -0.248393243020808, -0.112609040440504, 0.039230426343861, -0.068175866045984, 0.080060386788722, 0.104404253793483, -0.228253101599439, -0.040154508265654, -0.529154821492668, 0.290025026008395, -0.153772321788701, -0.297646354959656, -0.060354262233743, -0.354214037455003, -0.002450955641318, -0.137587030266902, 0.546839666242243, 0.286827105859665, -0.622195096687798, 0.112174032121290, -0.347876399682319, -0.062289955618691, 0.042390627762254, 0.188038886715664, -0.067340587756033, 0.394811956312274, -0.119681598187895, 0.082246490045299, 0.166367760075837, 0.021297148180290,
              0.194044051507049, 0.028414994785474, -0.274618980430660, -0.556119917199373, 0.333677512947863, -0.308297391222891, -0.157519083289826, -0.068761419919207, -0.207348054360413, -0.488123001581634, -0.405064238833303, -0.267832656297302, 0.184654877113296, -0.348763244535639, 0.114133218516871, 0.046647310410861, -0.037448061379746, -0.191700813608677, 0.053032557953629, 0.153920649724157, -0.140230124553793, 0.326689629014307, 0.124596172452880, 0.358134768264307, 0.517273674221611, 0.258582247900155, 0.464207096139254, 0.675312299553036, 0.180357248272229, 0.949841434688489, 1.348488167590773, 1.033748432436740, 0.766480730061207, 1.004104822507222, 0.689478381642838, 1.469466365123965, 1.161616778804135, 1.049717800916015, 0.560353468409137, 0.785749995459990, 0.492629818617782, 0.480786713159886, 0.342582266602165, 0.155092019821635, 0.110779704976334, 0.211932446147119, -0.233868563416034, 0.269188279554741, 0.014279241242331, 0.144959574936465,
              -0.035977670079325, -0.053377388697520, -0.621288730205246, -0.579133893030911, -0.509375871330200, -0.443771792846066, -0.262561649704794, -0.690795844945770, -0.376476727244374, -0.646567525886742, -0.545453862974029, -0.737331029599258, -0.863356524609902, -0.999587056030288, -0.520449784922332, -0.284768937530767, -0.492638558132327, -0.484772875308572, -0.356821470769181, -0.483894088093232, -0.263082962303689, -0.115100093341048, 0.011460276428426, -0.015759525582041, 0.153206307363394, 0.027888186714345, 0.454248880264264, 0.078937229200031, 0.452240969472302, -0.179476588927807, 0.133126794825730, -0.063386425614646, 0.151898171437583, 0.150531497571156, -0.544270350104548, -0.329339479874019, -0.357645837480133, 0.103254940613092, 0.370530390988811, -0.078537231996253, 0.206433330783965, 0.139923859928838, -0.259182988909361, 0.103278091843221, -0.183876087352537, 0.383350575902967, -0.003671521133599, 0.413656274908137, -0.101422007640401, 0.152387211115204,
              -0.010482682570390, -0.500088354230213, -0.239945248738485, 0.158901711671557, -0.007761390943807, -0.273536604636277, -0.150261984316338, 0.068898339964688, -0.241549592389868, 0.250628969873903, -0.153099708586897, 0.459479577647973, -0.262516385743005, 0.057433792384061, -0.372433954653451, -0.172898841109938, -0.140117384116828, 0.108715534014115, 0.244101033292193, 0.083875449805433, -0.084327452327708, 0.212998593776710, 0.209034469216307, 0.039550296089759, 0.152497137452832, 0.113070487025604, -0.236682731966582, 0.200136074773537, -0.153870077056204, -0.140363118202116, 0.055039462147821, -0.065886856476677, -0.021779822816420, 0.160200938307122, 0.273255970335947, -0.037755629469779, 0.093839824083524, -0.047468838617167, 0.069692015258887, 0.122478522583009, -0.141551181421413, 0.081560751952353, 0.163313317765053, 0.036301051881262, 0.445870666388155, -0.138542788265973, -0.170482115582302, -0.423500744831214, 0.241775981101013, 0.231112228849608,
              -0.005445364728190, 0.239333096804148, 0.060826209656217, 0.087784142028061, 0.043509041985753, 0.125447164372142, 0.041060982502660, 0.712665432954476, -0.275648377124000, -0.447370635824221, -0.268779896895663, -0.256759220364613, -0.091639425999876, -0.025168317026489, -0.033211544432257, 0.161228147536247, 0.127683782599234, 0.222647170842516, 0.483876592525199, 0.349550948667915, -0.272556022384713, -0.529507932272342, 0.282686256568437, -0.397233588071275, 0.082838003753755, 0.079491340385948, 0.631886181500537, 0.062263291485072, -0.042791218131026, 0.147464659198675, 0.154436147060090, 0.114968929472846, -0.050214807369328, -0.199245331863983, 0.190000796414118, -0.220368909908778, -0.138224993739323, 0.457097756576978, 0.024040679585287, 0.098158740860673, 0.362667446631086, 0.067156806034876, 0.403998678496585, 0.064863450610995, 0.408803102600585, 0.317408975799710, 0.111294251938606, -0.047403611459246, -0.087283666671506, 0.110448898532891,
              0.063958069762364, 0.066852136931804, 0.410434331400259, 0.085651043564512, 0.441522364227579, 0.018224914126058, 0.389798682472973, 0.011621936190407, 0.181856313067359, 0.375923627263437, 0.025273409599192, 0.014726155759509, 0.620668744994286, 0.353096774133976, 0.002874745282744, 0.268638197523571, 0.011911244862166, 0.273928881955998, 0.446947201195775, -0.312616676094651, 0.341252815273105, 0.444058800156080, 0.086961992777276, 0.507185646456159, 0.104995654444834, -0.247603838303134, -0.491170179878143, -0.030621070017440, 0.226643829407493, 0.123137244043088, 0.142715215275731, -0.109431471239052, 0.066367681989534, -0.383771893877069, -0.168600654084429, -0.187749121520191, 0.146074272073760, 0.011794932764036, -0.274354497035491, 0.011339513509760, -0.159538994375643, -0.154568250870025, 0.227336790319530, 0.038847191582948, 0.109275941565712, 0.229870600080863, 0.053135448516939, 0.144977553032527, 0.177197889044126, 0.298301882523025,
              0.123807761831692, 0.357093684121215, 0.008880531085471, -0.009546045048998, 0.426947868572775, -0.126620825689839, -0.000713740036080, 0.229966769951599, 0.037452183158190, 0.351233361419244, 0.258530384892428, 0.072892572192701, -0.194424634577901, 0.141674024384826, -0.345655289870088, 0.061118668897472, 0.202109700791923, 0.053260424604250, 0.219919291058372, 0.509719062853511, 0.230983112172234, 0.066729361648957, 0.160415376605445, 0.106371338906324, -0.328680875871721, -0.104102804924858, 0.306171956196334, -0.010896051386583, 0.145605819361992, -0.251625018654834, 0.016129185577776, 0.150072987296446, -0.340378738716142, 0.086898157990016, -0.045460804614833, -0.234883691485373, -0.009383297204793, -0.474076123405612, -0.531994192045668, -0.294230832678739, -0.247633055121044, -0.293258081816851, -0.431356947382173, 0.072057022416253, -0.398545930066702, 0.027554712305845, 0.196766669089495, -0.000556696578459, 0.023277190014701, -0.094539264147439,
              -0.370669027764751, -0.010954646339574, 0.240206302920529, 0.434561233153335, -0.107551560606525, -0.406830684117445, 0.041586873115016, 0.094066477612680, -0.056737616176558, -0.287228072404698, 0.506083149885967, -0.589880877739623, -0.127493011449985, -0.330406397702525, -0.159032062415010, 0.079462854764924, 0.034511993612381, -0.177683768702807, 0.194250881679947, 0.155598481043003, 0.161845221129012, -0.106407920415088, 0.262145190134110, 0.165176771591794, 0.627193118296276, 0.265864909760256, 0.289230413331848, 0.013244706831403, -0.322096500735073, -0.092805311874408, -0.189447979124705, -0.140992229256857, 0.138784640000462, -0.139194515987591, -0.223778283870609, -0.102331930408518, -0.040221691684611, 0.102333607613864, -0.238158999279994, 0.079329368081153, 0.019505020244519, 0.331096362290056, -0.053292621605396, -0.033619661138857, -0.292838954480074, -0.346315670798810, 0.077627079650125, -0.062372266118485, 0.125936013934332, -0.223165350869259;
    Eigen::Matrix<double, 86, 1> b;
    b << 0.000860924329535, 0.000844318874507, 0.000892143491858, 0.000554685704529, -0.000298926386351, -0.001689157223846, -0.003479401371185, -0.005370591982409, -0.006933988500254, -0.007705666495875, -0.007310771766441, -0.005596002171404, -0.002722913244462, 0.000807657243403, 0.004227835076939, 0.006665512886909, 0.007371015375589, 0.005948937877282, 0.002530468752912, -0.002177113875074, -0.006996782247813, -0.010541036181323, -0.011572890818493, -0.009383025861311, -0.004076644509395, 0.003324258473308, 0.011021381783394, 0.016819792361980, 0.018678586188679, 0.015307102657076, 0.006654395853404, -0.005852259565666, -0.019414108046905, -0.030329261773760, -0.034747002520610, -0.029553397946976, -0.013186020610102, 0.013823048154389, 0.048726374649592, 0.086921162032327, 0.122738450930179, 0.150506051836925, 0.165659887664182, 0.165659887664182, 0.150506051836925, 0.122738450930179, 0.086921162032327, 0.048726374649592, 0.013823048154389, -0.013186020610102,
         -0.029553397946976, -0.034747002520610, -0.030329261773760, -0.019414108046905, -0.005852259565666, 0.006654395853404, 0.015307102657076, 0.018678586188679, 0.016819792361980, 0.011021381783394, 0.003324258473308, -0.004076644509395, -0.009383025861311, -0.011572890818493, -0.010541036181323, -0.006996782247813, -0.002177113875074, 0.002530468752912, 0.005948937877282, 0.007371015375589, 0.006665512886909, 0.004227835076939, 0.000807657243403, -0.002722913244462, -0.005596002171404, -0.007310771766441, -0.007705666495875, -0.006933988500254, -0.005370591982409, -0.003479401371185, -0.001689157223846, -0.000298926386351, 0.000554685704529, 0.000892143491858, 0.000844318874507, 0.000860924329535;
    Eigen::Matrix<double, 1, 1> a; a << 1.0;
    signal = btkEigen::filtfilt(b, a, signal);
    Eigen::Matrix<double, 500, 1> ref;
    ref << 0.040810940881405, 0.050228239483528, 0.056505066846485, 0.057043728837096, 0.050242725087918, 0.035782544499711, 0.014692489524521, -0.010807352532408, -0.037671185798311, -0.062533632990239, -0.082269238074747, -0.094507816886839, -0.098014359240653, -0.092862350351857, -0.080373495450794, -0.062837567240186, -0.043072205683004, -0.023912626590355, -0.007738357734125, 0.003866432276632, 0.010256423411788, 0.011645785294514, 0.008843443958041, 0.002880207851622, -0.005369491741547, -0.015462132498147, -0.027474622449244, -0.041873769483486, -0.059192989597894, -0.079603405859449, -0.102494115406370, -0.126207702744877, -0.148021709055749, -0.164444201249945, -0.171786542705231, -0.166916748304938, -0.148029440137007, -0.115247500328526, -0.070884139836946, -0.019267053028182, 0.033893062063123, 0.082490813249148, 0.121178087825138, 0.146444969222562, 0.157379807018205, 0.155914390595262, 0.146477004507809, 0.135088329752639, 0.128077554847706, 0.130691511071479,
           0.145893762504532, 0.173640522813727, 0.210808346856858, 0.251815784072481, 0.289819642020297, 0.318229114346142, 0.332208429570393, 0.329817218265288, 0.312531329513378, 0.284991365436616, 0.254043956029532, 0.227255391437397, 0.211249117679594, 0.210226738738654, 0.225025589744142, 0.252926775348325, 0.288267869279916, 0.323720379199654, 0.351948727122932, 0.367261296406887, 0.366879919155996, 0.351532814658771, 0.325233904542751, 0.294307301269187, 0.265886966867097, 0.246243324897768, 0.239331292101341, 0.245895143432371, 0.263327874860584, 0.286316927706979, 0.308098082324743, 0.322020046596327, 0.323041018300794, 0.308802958263453, 0.280038910277687, 0.240236555962417, 0.194661327554524, 0.148994589998430, 0.107942109787366, 0.074159607126547, 0.047766861129534, 0.026560669219443, 0.006875205548252, -0.015150198067523, -0.042213049349286, -0.074773898670654, -0.110554321552896, -0.144764031679180, -0.171043207278397, -0.182913084442727,
           -0.175411689124163, -0.146526026422486, -0.098060246274099, -0.035715879817765, 0.031688287313303, 0.093717801411085, 0.140253375413893, 0.163447270957962, 0.159298834362110, 0.128501440892052, 0.076381234579339, 0.011923430154756, -0.053914644826948, -0.110271906093025, -0.148407032070361, -0.163276585114380, -0.154363761121279, -0.125599766152762, -0.084424304921571, -0.040191506316196, -0.002263253762586, 0.021819651295996, 0.027721124457649, 0.014994817872492, -0.013046465364027, -0.050206397635156, -0.088819656539855, -0.121387427614693, -0.142088020882707, -0.147855136337034, -0.138828189713307, -0.118098941470961, -0.090857384942542, -0.063136590311775, -0.040446747464806, -0.026600276319057, -0.022965609302350, -0.028304248214260, -0.039193873474016, -0.050932334389314, -0.058710167216538, -0.058775817845094, -0.049356554725444, -0.031122241984667, -0.007117837506820, 0.017830472450660, 0.038077597922717, 0.048305740457092, 0.044591413264164, 0.025195510882799,
           -0.009083232923548, -0.055043999729073, -0.107656798035622, -0.160940292689184, -0.208958416513413, -0.246733957256139, -0.270911323186776, -0.280075796779663, -0.274695087442826, -0.256750543695981, -0.229165180218459, -0.195173724760399, -0.157761782777854, -0.119275444022690, -0.081230541195111, -0.044322504917107, -0.008557542334622, 0.026561591556419, 0.061873522399415, 0.098464131967450, 0.137646072548022, 0.180971556353365, 0.230213469666022, 0.287253964489719, 0.353828906468143, 0.431131354692100, 0.519325069929241, 0.617064597139707, 0.721152263557268, 0.826454291201478, 0.926158476957531, 1.012404971486348, 1.077227811010789, 1.113670422281888, 1.116892010424473, 1.085049979597763, 1.019772522134488, 0.926107477670085, 0.811910599439223, 0.686767718105146, 0.560614138090394, 0.442301345099651, 0.338357169343321, 0.252166616727289, 0.183713648876552, 0.129919222451647, 0.085495580615167, 0.044143760016717, -0.000151804583359, -0.051969447723350,
           -0.113659208858468, -0.185037548931149, -0.263597210117486, -0.345152181322832, -0.424756400050200, -0.497681416045958, -0.560244700960154, -0.610324022557978, -0.647464705207623, -0.672594690125649, -0.687435636813423, -0.693774304815150, -0.692779768503112, -0.684538129886538, -0.667921989953501, -0.640835883701240, -0.600783158383979, -0.545642470715491, -0.474474500115476, -0.388181348583206, -0.289863484612283, -0.184778284221242, -0.079881812528233, 0.016981837041497, 0.098116823674212, 0.157059298541505, 0.189536234808157, 0.194128959763086, 0.172547734581734, 0.129460718166346, 0.071919601395654, 0.008454881676411, -0.052009906466712, -0.101287986280283, -0.132938843125032, -0.143034876844339, -0.130594375082096, -0.097626883977897, -0.048804939926850, 0.009203996789603, 0.068647243745244, 0.121729122678724, 0.161647872639562, 0.183498933884199, 0.184910771666517, 0.166331425032126, 0.130906803378466, 0.083970273319565, 0.032198138833371, -0.017430518169930,
           -0.058724317451945, -0.087222621784607, -0.100844742880875, -0.100122492075882, -0.087966695344974, -0.069010747673460, -0.048650114533448, -0.031955887026845, -0.022671863792397, -0.022490139722892, -0.030753230035410, -0.044632857071376, -0.059762721306727, -0.071180986648862, -0.074408281664551, -0.066427899543541, -0.046378599207628, -0.015816573445533, 0.021500584284306, 0.060268975870071, 0.094596212757202, 0.119077987012325, 0.129787232953781, 0.124995316106255, 0.105497600289685, 0.074493325431587, 0.037057304476543, -0.000700563254573, -0.032637548090570, -0.053567502290125, -0.060089677929060, -0.051125849427871, -0.028088991900765, 0.005331026645395, 0.043738869791542, 0.080876470668785, 0.110618513752481, 0.127976325099848, 0.129963020639457, 0.116168290700201, 0.088941775665859, 0.053116493093368, 0.015281938777827, -0.017305575663745, -0.038017403669176, -0.042132128362042, -0.027858199210620, 0.003117428602859, 0.045709700427076, 0.092182930606033,
           0.133477553595496, 0.160894371576738, 0.167820232185414, 0.151150690514945, 0.112090116196325, 0.056127036560707, -0.007857740395589, -0.069206828649843, -0.117525128429613, -0.144717373629374, -0.146609379069435, -0.123782270375577, -0.081431086311244, -0.028260259505490, 0.025356343476050, 0.069558072831827, 0.097040726783417, 0.104514385802784, 0.093248044208030, 0.068588083174351, 0.038566348462983, 0.011927428912051, -0.003965355374709, -0.004857886634424, 0.009444830777980, 0.035107730336621, 0.065279015587722, 0.091829853841661, 0.107412380147492, 0.107333994099416, 0.090812426246984, 0.061297802724625, 0.025787884455774, -0.006715700725488, -0.027250362786596, -0.028970913683569, -0.008774134917185, 0.031890574153576, 0.087218378599386, 0.148211178973348, 0.204536643557771, 0.246676352294168, 0.267890212266517, 0.265570516794046, 0.241708653220642, 0.202387802080613, 0.156442249244680, 0.113583471071120, 0.082416994281239, 0.068761279181842,
           0.074621612514731, 0.097997579638930, 0.133529208103881, 0.173803169763348, 0.211011906835000, 0.238590720040365, 0.252497177277527, 0.251871395411872, 0.238983920352605, 0.218509520641490, 0.196332789447768, 0.178159117120638, 0.168241228954239, 0.168488990835239, 0.178137303636124, 0.194008024840335, 0.211288071986551, 0.224630920968725, 0.229326623598989, 0.222291450693705, 0.202672763967600, 0.171949174337112, 0.133536476567433, 0.091999645620159, 0.052056348134063, 0.017606905426100, -0.009010198394707, -0.027368049930827, -0.038854563342977, -0.046156273950882, -0.052460740209049, -0.060564770907448, -0.072099620159422, -0.087052239422536, -0.103693936384490, -0.118933196049906, -0.129009459322823, -0.130368913321120, -0.120517236922020, -0.098653840357053, -0.065940694502913, -0.025337326973962, 0.018952368910265, 0.062297936153636, 0.100537634363121, 0.130734474114451, 0.151633763709881, 0.163714941707550, 0.168838886136684, 0.169595236499922,
           0.168517720996684, 0.167376381677961, 0.166728665889236, 0.165850170306388, 0.163061114108945, 0.156362678578367, 0.144216672982620, 0.126243477037792, 0.103647655503227, 0.079226337269859, 0.056922240717346, 0.041014556784184, 0.035116762556211, 0.041234823517568, 0.059116222662844, 0.086084895875639, 0.117420464584499, 0.147233927782634, 0.169654703247172, 0.180062575094624, 0.176082649366131, 0.158102704939762, 0.129172913491309, 0.094302919931397, 0.059300203150657, 0.029412883392675, 0.008088720545323, -0.003852641971252, -0.008435713141562, -0.010067807298479, -0.014491013077521, -0.027379473190756, -0.052894130739248, -0.092526834324519, -0.144505058440394, -0.203896961851672, -0.263416172151776, -0.314757927794857, -0.350184399946966, -0.364029319761315, -0.353801143945012, -0.320659759099552, -0.269178836686870, -0.206455504857355, -0.140772129147275, -0.080092035641332, -0.030713332282054, 0.003660592391128, 0.022264281864217, 0.026993174782433,
           0.021610392267629, 0.010648050831706, -0.001731949526395, -0.012658644107970, -0.021049612871056, -0.027600727600457, -0.034290824184158, -0.043540431078158, -0.057242724783447, -0.075911697714719, -0.098156498949813, -0.120630763518269, -0.138477597117871, -0.146211307743982, -0.138842204199855, -0.113028772179986, -0.068006438126455, -0.006091728307946, 0.067360287030659, 0.144563545878455, 0.216384358044692, 0.273720654629018, 0.308934812179812, 0.317093992489683, 0.296801019918489, 0.250467032272374, 0.183986521621788, 0.105860716809875, 0.025928583277328, -0.046090475691742, -0.102000973421402, -0.136256392293354, -0.146641742460962, -0.134416233260096, -0.103919450206127, -0.061732519884843, -0.015546804574833, 0.027056588791032, 0.059719011145361, 0.078130738694671, 0.080456708226332, 0.067324976932425, 0.041402459734139, 0.006673687556851, -0.032438926172749, -0.071936763665954, -0.108936427863360, -0.142071826753062, -0.171542923237618, -0.198826043502748;
    for (int i = 0 ; i < signal.rows() ; ++i)
    {
      TSM_ASSERT_DELTA("Row #" + btk::ToString(i), signal(i), ref(i), 5e-15); // 5e-15: Due to the differences in the computation of the initial state of the filter?
    }
  }
};

CXXTEST_SUITE_REGISTRATION(EigenFiltFiltTest)
CXXTEST_TEST_REGISTRATION(EigenFiltFiltTest, Butterworth_LowPass_2_0Dot5)
CXXTEST_TEST_REGISTRATION(EigenFiltFiltTest, Butterworth_LowPass_7_0Dot4)
CXXTEST_TEST_REGISTRATION(EigenFiltFiltTest, FiltFiltWindowAverage_FixedSize)
CXXTEST_TEST_REGISTRATION(EigenFiltFiltTest, FiltFiltOrder2_FixedSize)
CXXTEST_TEST_REGISTRATION(EigenFiltFiltTest, FiltFiltECG_FixedSize)

#endif // EigenFiltFiltTest_h